610 - Street directions (Grafos, DFS) && 10986 - Sending email (Grafos, Algoritmo...
[and.git] / 572 - Oil deposits / 1959.cpp
blob26d20643ddb6637d38da57233579129adba84419
1 /*
2 572 - Oil deposits (UVa Online Judge)
3 1959 - Oil deposits (TJU Online Judge)
4 */
5 #include <iostream>
7 using namespace std;
9 int di[] = {-1, -1, -1, +0, +1, +1, +1, +0};
10 int dj[] = {-1, +0, +1, +1, +1, +0, -1, -1};
12 int r, c;
14 char g[100][100];
15 bool v[100][100];
17 void dfs(const int &i, const int &j){
18 if ( (0 <= i && i < r && 0 <= j && j < c) == false){
19 return;
21 if (v[i][j] || g[i][j] == '*') return;
23 v[i][j] = true;
25 for (int k=0; k<8; ++k){
26 dfs(i + di[k], j + dj[k]);
31 int main(){
32 while (cin >> r >> c && (r+c)){
33 for (int i =0; i<r; ++i){
34 for (int j=0; j<c; ++j){
35 cin >> g[i][j];
36 v[i][j] = false;
40 int t = 0;
41 for (int i =0; i<r; ++i){
42 for (int j=0; j<c; ++j){
43 if (!v[i][j] && g[i][j] == '@'){
44 ++t;
45 dfs(i, j);
50 cout << t << endl;
52 return 0;